package TestDemo3;

import java.util.LinkedList;
import java.util.Queue;
import java.util.*;

public class Test {
    public static boolean isValid (String s) {
        // write code here
        int index=0;
        if(s.length() == 1) return false;
        if(s.length() == 0) return true;

        Stack<Character> stack=new Stack();
        while(index < s.length()){
            if(
                    s.charAt(index) != '}' && s.charAt(index) != ')' && s.charAt(index) != ']'
            ){
                stack.push(s.charAt(index));
            }else {
                if(stack.isEmpty()) return false;
                switch (s.charAt(index)){
                    case '}':
                        if(stack.peek() != '{') return false;
                        stack.pop();
                        break;
                    case ')':
                        if(stack.peek() != '(') return false;
                        stack.pop();
                        break;
                    case ']':
                        if(stack.peek() != '[') return false;
                        stack.pop();
                        break;
                }
            }
            index++;
        }
        if(stack.isEmpty()) return true;
        return false;


    }

    public static void main(String[] args) {
        String s="{}[]()";
        boolean ret=isValid(s);
        System.out.println(ret);
    }

}
